/**
 * Created by xuy on 2017/3/21.
 */

/**
 * 手机号码格式判断
 * @param tel
 * @returns {boolean}
 */
function checkMobile(tel) {
    var reg = /(^1[3|4|5|7|8][0-9]{9}$)/;
    if (reg.test(tel)) {
        return true;
    }else{
        return false;
    }
}

/**
 * 检查密码强度
 * @param password
 * @returns {strength}
 */
function checkPwdStrength(password){
    var weight = 0;
    var rules=[{
        reg:/\d+/,
        weight:2
    },{
        reg:/[a-z]+/,
        weight:8
    },{
        reg:/[A-Z]+/,
        weight:8
    },{
        reg:/\W/,
        weight:16
    }];

    var strongLevel={
        '0-15':'weak',
        '15-23':'medium',
        '23-31':'strong'
    };
    var length = password.length;
    if(length >=6){
        weight = 7;
    }
    for(var j=rules.length-1;j>=0;j--){
        if(rules[j].reg.test(password)){
            if(length<6){
                weight|=7;
            }else{
                weight|=rules[j].weight;
            }

        }
    }

    var key='23-31';
    if(weight<=10)key='0-15';
    else if(weight<=20)key='15-23';
    return strongLevel[key];

}
//判断是否有特殊字符
function checkChar(char){
    var regArray=new Array("◎","■","●","№","↑","→","↓"+
        "!","@","#","$","%","^","&","*","(",")","_","-","+","=","|","[","]","？","~","`"+
        "!","<",">","‰","→","←","↑","↓","¤","§","＃","＆","＆","＼","≡","≠"+
        "≈","∈","∪","∏","∑","∧","∨","⊥","‖","‖","∠","⊙","≌","≌","√","∝","∞","∮"+
        "∫","≯","≮","＞","≥","≤","≠","±","＋","÷","×","/","Ⅱ","Ⅰ","Ⅲ","Ⅳ","Ⅴ","Ⅵ","Ⅶ","Ⅷ","Ⅹ","Ⅻ","一","二"+
        "╄","╅","╇","┻","┻","┇","┭","┷","┦","┣","┝","┤","┷","┷","┹","╉","╇","【","】"+
        "三","四","五","六","七","八","九","十","①","②","③","④","⑤","⑥","⑦","⑧","⑨","⑩","┌","├","┬","┼","┍","┕","┗","┏","┅","—"+
        "〖","〗","←","〓","☆","§","□","‰","◇","＾","＠","△","▲","＃","℃","※",".","≈","￠");
    var iuu=regArray.length;
    //console.log(char);
    for(var iu=0;iu<=iuu;iu++){
        if (char.indexOf(regArray[iu])!=-1){
            return false;
        }
    }
    return true;
}
//判断字符串长度
function strlen(str){
    var len = 0;
    for (var i=0; i<str.length; i++) {
        var c = str.charCodeAt(i);
        //单字节加1
        if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {
            len++;
        }
        else {
            len+=2;
        }
    }
    return len;
}

//获取url中的参数
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}
